function matrixReshape(mat: number[][], r: number, c: number): number[][] {
  let len: number = mat.length * mat[0].length;
  let newArr: Array<number>[] = [];
  if (r * c != len) {
    return mat;
  }
  let temp: number[] = [];
  newArr.push([]);
  let k = 0;
  let m = 0;
  for (let i = 0; i < mat.length; i++) {
    for (let j = 0; j < mat[i].length; j++) {
      k++;
      newArr[m].push(mat[i][j]);
      if (k === c) {
        k = 0;
        m++;
        if (i === mat.length - 1 && j === mat[i].length - 1) {
        } else {
          newArr.push([]);
        }
      }
    }
  }
  return newArr;
}
console.log(matrixReshape([[1, 2]], 1, 2));
